<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class Controller extends CController
{
	/**
	 * @var string the default layout for the controller view. Defaults to 'column1',
	 * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
	 */
	public $layout='column1';
	/**
	 * @var array context menu items. This property will be assigned to {@link CMenu::items}.
	 */
	public $menu=array();
	/**
	 * @var array the breadcrumbs of the current page. The value of this property will
	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
	 * for more details on how to specify this property.
	 */
	public $breadcrumbs=array();
    protected $smarty = '';
	public function init() {
        $this->smarty = Yii::app()->smarty;
    }

    /**
     * @param $key
     * @param string $default
     * @return mixed
     * get 数据
     */
    protected function get($key, $default=''){
        return Yii::app()->request->getQuery($key, $default);
    }

    /**
     * @param $key
     * @param string $default
     * @return mixed
     * post数据
     */
    protected function post($key, $default=''){
        return Yii::app()->request->getPost($key, $default);
    }

    /**
     * request数据
     */
    protected function request($key, $default=''){
        return Yii::app()->request->getParam($key, $default);
    }
    /**
     * ajax返回数据
     */
    protected function _ajax($data){
        if ($callback = $this->request('callback')) {
            echo $callback . '(' . json_encode($data) . ')';
        } else {
            echo json_encode($data);
        }
    }
    /**
     * 错误提示
     */
    protected function Error($error_code){
        include YII::app()->basePath.'/config/code.php';
        return isset($ERROR_CODE[$error_code]) ? $ERROR_CODE[$error_code] : '未知错误';
    }
	
	/**
	 * 开启PHPExcel的支持
	 * 在需要使用PHPExcel的地方，显示调用一下此方法，不直接放在init中，是不想在其他不需要调用PHPExcel的地方也加载PHPExcel
	 */
	protected function enablePHPExcel(){
		Yii::$enableIncludePath = false;  
		Yii::import('application.extensions.PHPExcel', true);
	}
}